package org.dromara.learning_lhz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.learning_lhz.entity.AsFormativeTestEntity;
import org.dromara.learning_lhz.entity.AsStudyEntity;
import org.dromara.learning_lhz.mapper.FormativeTestMapper;
import org.dromara.learning_lhz.service.FormativeTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class FormativeTestServiceImpl extends ServiceImpl<FormativeTestMapper, AsFormativeTestEntity> implements FormativeTestService {

    @Autowired
    protected FormativeTestMapper formativeTestMapper;

    @Override
    public List<AsFormativeTestEntity> selFormative(AsFormativeTestEntity asFormativeTestEntity) {
        LambdaQueryWrapper<AsFormativeTestEntity> queryWrapper = new LambdaQueryWrapper<>();

        if (Objects.nonNull(asFormativeTestEntity.getSubject())) {
            queryWrapper.eq(AsFormativeTestEntity::getSubject, asFormativeTestEntity.getSubject());
        }

        if (Objects.nonNull(asFormativeTestEntity.getSemester())) {
            queryWrapper.eq(AsFormativeTestEntity::getSemester, asFormativeTestEntity.getSemester());
        }

        if (Objects.nonNull(asFormativeTestEntity.getGrade())) {
            queryWrapper.eq(AsFormativeTestEntity::getGrade, asFormativeTestEntity.getGrade());
        }

        if (Objects.nonNull(asFormativeTestEntity.getLearningStage())) {
            queryWrapper.eq(AsFormativeTestEntity::getLearningStage, asFormativeTestEntity.getLearningStage());
        }

        return formativeTestMapper.selectList(queryWrapper);
    }

    @Override
    public void addFormative(AsFormativeTestEntity asFormativeTestEntity) {
        LoginHelper.getLoginUser().getUsername();
        asFormativeTestEntity.setCreateBy(LoginHelper.getUserId());
        this.save(asFormativeTestEntity);
    }
}
